import 'package:extended_image/extended_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:gd_assistant/globalConfig.dart';
import 'package:gd_assistant/model/extensionModel.dart';
import 'package:gd_assistant/model/healthRecordModel.dart';
import 'package:gd_assistant/page/public/colors.dart';
import 'package:gd_assistant/page/public/publicView.dart';
import 'package:gd_assistant/page/public/themeUtils.dart';
import 'package:gd_assistant/util/RelativeDateFormat.dart';

//健康档案的 item
class healthRecordItem extends StatelessWidget {
  bool isDark = false;
  healthRecordItem({Key key, this.health, this.onTap}): super(key: key);
  HealthRecordModel health;
  Function onTap = (){};
  @override
  Widget build(BuildContext context) {
    isDark = ThemeUtils.isDark(context);
    String weekStr = health.weekStr.length > 0 ? health.weekStr + ": " : "";
    return GestureDetector(
      onTap: onTap,
      child: Container(
        margin: EdgeInsets.only(top: 10),
        color: isDark ? Colours.dark_bg_gray : Colors.white,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              color: isDark ? Colours.dark_bg_gray : Colors.white,
              padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
              height: 50,
              child: Row(
                  children: <Widget>[
                    Icon(Icons.timer,color: Colors.blue),
                    Expanded(
                      flex: 1,
                      child: Padding(
                        padding: EdgeInsets.only(left: 5),
                        child: Text(weekStr+RelativeDateFormat.YMDformat(health.checkTime),style:TextStyle(fontSize: 16, color: isDark ? Colours.dark_text : Colors.black)),
                      )
                    ),
                    Icon(Icons.arrow_forward_ios, size: 15, color: Colors.grey)
                  ],
                ),
            ),
            ZLTagsView(titles: health.selectedReservations),
            Offstage(
              offstage: health.meProblem == null || health.meProblem.isEmpty,
              child: ZLLTTextView(
                title: "主诉及存在问题",
                text: health.meProblem 
              ),
            ),
            Offstage(
              offstage: health.checkDetail == null || health.checkDetail.isEmpty,
              child: ZLLTTextView(
                title: "检查结果",
                text: health.checkDetail
              ),
            ),
            Offstage(
              offstage: health.doctorSolution == null || health.doctorSolution.isEmpty,
              child: ZLLTTextView(
                title: "处理及用药",
                text: health.doctorSolution
              ),
            ),
            Offstage(
              offstage: health.otherPoints == null || health.otherPoints.isEmpty,
              child: ZLLTTextView(
                title: "其他注意事项",
                text: health.otherPoints
              ),
            ),
            Offstage(
              offstage:  health.checkImgs.length == 0,
              child: ZLImageSelectView(
                isEdit: false,
                isBig: false,
                title: "上传资料和图片",
                images: health.checkImgs.map((imgStr)=> GlobalConfig.qiNiuUri + imgStr).toList()
              )
            )
          ],
        ),
      ),
    );
     
  }
}

//预约地点选择 item
class appointmentTimeItem extends StatelessWidget {
  appointmentTimeItem({
    Key key,
    this.onTap,
    this.appointment
  }) : super(key: key);
  
  AppointmentTime appointment;
  Function onTap = (){};
  bool isDark = false;

  @override
  Widget build(BuildContext context) {
    isDark = ThemeUtils.isDark(context);
    return GestureDetector(
      onTap: onTap,
      child:  Container(
      color: isDark ? Colours.dark_bg_gray : Colors.white,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.fromLTRB(15, 15, 10, 15),
                  child: Icon(Icons.date_range,color: Colors.blue),
                ),
                Expanded(
                  child: Text(appointment.dateString,style: TextStyle(fontSize: 18,fontWeight: FontWeight.w500)),
                )
              ],
            ),
            Padding(
              padding: EdgeInsets.fromLTRB(18, 0, 18, 18),
              child: Text("出诊地点: " + appointment.visitPlanPlace,style: TextStyle(fontSize: 16, color: Colors.grey[600])),
            ),
          ],
        ),
      ),
    );
  }
}


//预约状态 item
class appointmentItem extends StatelessWidget {
  appointmentItem({
    Key key,
    this.appointment,
    this.onTap
  }) : super(key: key);

  Extension appointment;
  Function onTap = (){};
  bool isDark = false;
  @override
  Widget build(BuildContext context) {
    isDark = ThemeUtils.isDark(context);
    String statusStr = "";
    Color timeColor = Colors.black;
    Color iconColor = Colors.blue;
    switch (appointment.order.status) {
      case 200:
        statusStr = "未就诊";
        timeColor = Colors.black;
        iconColor = Colors.blue;
        break;
      case 300:
        statusStr = "已取消";
        timeColor = Colors.grey[400];
        iconColor = Colors.blue[200];
      break;
      case 400:
        statusStr = "已就诊";
        timeColor = Colors.grey[400];
        iconColor = Colors.blue[200];
      break;
      default:
    }
    return GestureDetector(
      onTap: onTap,
      child: Container(
        color: isDark ? Colours.dark_bg_gray : Colors.white,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.fromLTRB(15, 15, 10, 15),
                  child: Icon(Icons.date_range,color: iconColor),
                ),
                Expanded(
                  child: Text(appointment.order.workTimeStr,style: TextStyle(fontSize: 18,fontWeight: FontWeight.w500, color: timeColor)),
                ),
                Container(
                    padding: EdgeInsets.fromLTRB(10, 2, 10, 2),
                    margin: EdgeInsets.only(right: 15,top: 0),
                    decoration: BoxDecoration(
                      color: iconColor,
                      borderRadius: BorderRadius.all(Radius.circular(10))
                    ),
                    child: Text(
                      statusStr,
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 13
                      )
                    ),
                ),
              ],
            ),
            Padding(
              padding: EdgeInsets.fromLTRB(18, 0, 18, 10),
              child: Text("出诊地点: ${appointment.order.address}",style: TextStyle(fontSize: 16, color: timeColor)),
            ),
            Container(
              margin: EdgeInsets.fromLTRB(15, 5, 15, 15),
              color: isDark ? Colours.dark_bg_color : Colors.grey[100],
              child: Row(
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(34),
                      child: ExtendedImage.network(
                        GlobalConfig.qiNiuUri + appointment.doctor.avatar,
                        height: 68,
                        width: 68,
                      ),
                    )
                  ),
                 Expanded(
                   flex: 1,
                   child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          Text(appointment.doctor.name,style: TextStyle(fontSize: 16,fontWeight: FontWeight.w500)),
                          Container(
                              padding: EdgeInsets.fromLTRB(5, 1, 5, 1),
                              margin: EdgeInsets.only(right: 10,top: 0,left: 10),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.all(Radius.circular(10)),
                                border: Border.all(color: Colors.blue, width: 0.5)
                              ),
                              child: Text(
                                appointment.doctor.title,
                                style: TextStyle(
                                  color: Colors.blue,
                                  fontSize: 11
                                )
                              ),
                          ),
                        ],
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 8,right: 10),
                      ),
                      Text("${appointment.doctor.department} | ${appointment.doctor.hospital}",style: TextStyle(fontSize: 15, color: Colors.grey[600]),maxLines: 1,overflow: TextOverflow.ellipsis)
                    ],
                  )
                 )
                ],
              ),
            )
          ],
        ),
      )
    );
  }
}